home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / irit / objects2.c < prev    next >
C/C++ Source or Header  |  1995-12-30  |  44KB  |  960 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d (not only polygonal) solid modeller.             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. *   Module to handle the objects list - fetch, insert, delete etc...         *
  7. *****************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <math.h>
  13. #include "program.h"
  14. #include "allocate.h"
  15. #include "attribut.h"
  16. #include "primitiv.h"
  17. #include "geomat3d.h"
  18. #include "objects.h"
  19. #include "freeform.h"
  20. #include "windows.h"
  21.  
  22. static int
  23.     GlblDumpLvl = DEFAULT_DUMPLVL;
  24.  
  25. static void UpdateLoadedHierarchy(IPObjectStruct *PObj, IPObjectStruct *Root);
  26. static int MatGenMatGeneric(IPObjectStruct *LstObjList, MatrixType Mat);
  27.  
  28. /*****************************************************************************
  29. * DESCRIPTION:                                                               M
  30. * Frees an Object - delete it from global active list and free all it memory M
  31. *                                                                            *
  32. * PARAMETERS:                                                                M
  33. *   PObj:       Object to free.                                              M
  34. *                                                                            *
  35. * RETURN VALUE:                                                              M
  36. *   void                                                                     M
  37. *                                                                            *
  38. * KEYWORDS:                                                                  M
  39. *   FreeObject                                                               M
  40. *****************************************************************************/
  41. void FreeObject(IPObjectStruct *PObj)
  42. {
  43.     /* Force free the object. Since the reference count should be actually   */
  44.     /* two (second for the parsing tree reference) we decrement it here.     */
  45.     if (PObj -> Count == 2) {
  46.     PObj -> Count = 1;
  47.     DeleteObject(PObj, TRUE);
  48.     }
  49.     else {
  50.     /* Reduce the reference count by two - one for the parsing tree      */
  51.     /* this routine was called from and one for the fact this object     */
  52.     /* reference count is to be deleted since this routine was called.   */
  53.     DeleteObject(PObj, FALSE);
  54.     PObj -> Count -= 2;
  55.     }
  56. }
  57.  
  58. /*****************************************************************************
  59. * DESCRIPTION:                                                               M
  60. * Delete object by its pointer - scans the object linear list.             M
  61. *   The deleted object is freed only if Free = TRUE.                 M
  62. *                                                                            *
  63. * PARAMETERS:                                                                M
  64. *   PObj:      Object to delete from global object list.                     M
  65. *   Free:      Do we want to free it as well?                                M
  66. *                                                                            *
  67. * RETURN VALUE:                                                              M
  68. *   void                                                                     M
  69. *                                                                            *
  70. * KEYWORDS:                                                                  M
  71. *   DeleteObject                                                             M
  72. *****************************************************************************/
  73. void DeleteObject(IPObjectStruct *PObj, int Free)
  74. {
  75.     IPObjectStruct
  76.     *PObjScan = GlblObjList;
  77.  
  78.     if (GlblObjList == NULL)
  79.     return;
  80.  
  81.     if (PObj == GlblObjList) {       /* If it is the first one - special case. */
  82.     GlblObjList = GlblObjList->Pnext;
  83.     if (Free)
  84.         IPFreeObject(PObj);
  85.     return;
  86.     }
  87.  
  88.     while (PObjScan->Pnext) {
  89.     if (PObj == PObjScan -> Pnext) {
  90.         /* Delete it from list. */
  91.         PObjScan -> Pnext = PObjScan -> Pnext -> Pnext;
  92.         if (Free)
  93.         IPFreeObject(PObj);                 /* And free it. */
  94.         return;
  95.     }
  96.     PObjScan = PObjScan->Pnext;
  97.     }
  98. }
  99.  
  100. /*****************************************************************************
  101. * DESCRIPTION:                                                               M
  102. * Inserts an object by its pointer - as first in object linear list.         M
  103. *    It is assumed the object is not in the object list already.         M
  104. *                                                                            *
  105. * PARAMETERS:                                                                M
  106. *   PObj:     Object to insert to global list.                               M
  107. *                                                                            *
  108. * RETURN VALUE:                                                              M
  109. *   void                                                                     M
  110. *                                                                            *
  111. * KEYWORDS:                                                                  M
  112. *   InsertObject                                                             M
  113. *****************************************************************************/
  114. void InsertObject(IPObjectStruct *PObj)
  115. {
  116.     PObj -> Pnext = GlblObjList;
  117.     GlblObjList = PObj;
  118. }
  119.  
  120. /*****************************************************************************
  121. * DESCRIPTION:                                                               M
  122. * Sets dumping level values for variables and expression's results.          M
  123. *                                                                            *
  124. * PARAMETERS:                                                                M
  125. *   DumpLvl:  New dump level.                                     M
  126. *                                                                            *
  127. * RETURN VALUE:                                                              M
  128. *   void                                                                     M
  129. *                                                                            *
  130. * KEYWORDS:                                                                  M
  131. *   SetDumpLevel                                                             M
  132. *****************************************************************************/
  133. void SetDumpLevel(int DumpLvl)
  134. {
  135.     GlblDumpLvl = DumpLvl;
  136. }
  137.  
  138. /*****************************************************************************
  139. * DESCRIPTION:                                                               M
  140. * Print some usefull info on the given object.                          M
  141. *                                                                            *
  142. * PARAMETERS:                                                                M
  143. *   PObj:      To print out.                                                 M
  144. *                                                                            *
  145. * RETURN VALUE:                                                              M
  146. *   void                                                                     M
  147. *                                                                            *
  148. * KEYWORDS:                                                                  M
  149. *   PrintObject                                                              M
  150. *****************************************************************************/
  151. void PrintObject(IPObjectStruct *PObj)
  152. {
  153.     int Count = PObj -> Count;
  154.     char Line[LINE_LEN_LONG],
  155.     *Name = (int) strlen(PObj -> Name) > 0 ? PObj -> Name : "NONE";
  156.  
  157.     switch (PObj -> ObjType) {
  158.     case IP_OBJ_UNDEF:
  159.         sprintf(Line, "%-10s (%d) - Undefined type", Name, Count);
  160.         WndwInputWindowPutStr(Line);
  161.         break;
  162.     case IP_OBJ_POLY:
  163.         sprintf(Line, "%-10s (%d) - Poly      type", Name, Count);
  164.         WndwInputWindowPutStr(Line);
  165.         if (GlblDumpLvl >= 3)
  166.         SaveObjectInFile(NULL, PObj);
  167.         break;
  168.     case IP_OBJ_NUMERIC:
  169.         sprintf(Line, "%-10s (%d) - Numeric   type", Name, Count);
  170.         WndwInputWindowPutStr(Line);
  171.         if (GlblDumpLvl >= 1)
  172.         SaveObjectInFile(NULL, PObj);
  173.         break;
  174.     case IP_OBJ_POINT:
  175.         sprintf(Line, "%-10s (%d) - Point     type", Name, Count);
  176.         WndwInputWindowPutStr(Line);
  177.         if (GlblDumpLvl >= 1)
  178.         SaveObjectInFile(NULL, PObj);
  179.         break;
  180.     case IP_OBJ_VECTOR:
  181.         sprintf(Line, "%-10s (%d) - Vector    type", Name, Count);
  182.         WndwInputWindowPutStr(Line);
  183.         if (GlblDumpLvl >= 1)
  184.         SaveObjectInFile(NULL, PObj);
  185.         break;
  186.     case IP_OBJ_PLANE:
  187.         sprintf(Line, "%-10s (%d) - Plane     type", Name, Count);
  188.         WndwInputWindowPutStr(Line);
  189.         if (GlblDumpLvl >= 1)
  190.         SaveObjectInFile(NULL, PObj);
  191.         break;
  192.     case IP_OBJ_CTLPT:
  193.         sprintf(Line, "%-10s (%d) - CtlPt     type", Name, Count);
  194.         WndwInputWindowPutStr(Line);
  195.         if (GlblDumpLvl >= 1)
  196.         SaveObjectInFile(NULL, PObj);
  197.         break;
  198.     case IP_OBJ_MATRIX:
  199.         sprintf(Line, "%-10s (%d) - Matrix    type", Name, Count);
  200.         WndwInputWindowPutStr(Line);
  201.         if (GlblDumpLvl >= 1)
  202.         SaveObjectInFile(NULL, PObj);
  203.         break;
  204.     case IP_OBJ_STRING:
  205.         sprintf(Line, "%-10s (%d) - String    type", Name, Count);
  206.         WndwInputWindowPutStr(Line);
  207.         if (GlblDumpLvl >= 1)
  208.         SaveObjectInFile(NULL, PObj);
  209.         break;
  210.     case IP_OBJ_LIST_OBJ:
  211.         sprintf(Line, "%-10s (%d) - Object List type", Name, Count);
  212.         WndwInputWindowPutStr(Line);
  213.         if (GlblDumpLvl >= 4)
  214.         SaveObjectInFile(NULL, PObj);
  215.         break;
  216.     case IP_OBJ_CURVE:
  217.         sprintf(Line, "%-10s (%d) - Curve     type", Name, Count);
  218.         WndwInputWindowPutStr(Line);
  219.         if (GlblDumpLvl >= 2) {
  220.         SaveObjectInFile(NULL, PObj);
  221.         }
  222.         break;
  223.     case IP_OBJ_SURFACE:
  224.         sprintf(Line, "%-10s (%d) - Surface   type", Name, Count);
  225.         WndwInputWindowPutStr(Line);
  226.         if (GlblDumpLvl >= 2) {
  227.         SaveObjectInFile(NULL, PObj);
  228.         }
  229.         break;
  230.     case IP_OBJ_TRIMSRF:
  231.         sprintf(Line, "%-10s (%d) - Trimmed Srf type", Name, Count);
  232.         WndwInputWindowPutStr(Line);
  233.         if (GlblDumpLvl >= 2) {
  234.         SaveObjectInFile(NULL, PObj);
  235.         }
  236.         break;
  237.     case IP_OBJ_TRIVAR:
  238.         sprintf(Line, "%-10s (%d) - Trivariate type", Name, Count);
  239.         WndwInputWindowPutStr(Line);
  240.         if (GlblDumpLvl >= 2) {
  241.         SaveObjectInFile(NULL, PObj);
  242.         }
  243.         break;
  244.     default:
  245.         sprintf(Line, "%-10s (%d) - Obj type error, type = %d",
  246.                 Name, Count, PObj->ObjType);
  247.         WndwInputWindowPutStr(Line);
  248.         break;
  249.     }
  250. }
  251.  
  252. /*****************************************************************************
  253. * DESCRIPTION:                                                               M
  254. * Gets a string description of the object type.                          M
  255. *                                                                            *
  256. * PARAMETERS:                                                                M
  257. *   PObj:        Object to get a string description on.                      M
  258. *                                                                            *
  259. * RETURN VALUE:                                                              M
  260. *   char *:      A string describing PObj.                                   M
  261. *                                                                            *
  262. * KEYWORDS:                                                                  M
  263. *   GetObjectTypeAsString                                                    M
  264. *****************************************************************************/
  265. char *GetObjectTypeAsString(IPObjectStruct *PObj)
  266. {
  267.     if (PObj == NULL)
  268.     return "Unknown";
  269.  
  270.     switch (PObj -> ObjType) {
  271.     case IP_OBJ_POLY:
  272.         return (IP_IS_POLYGON_OBJ(PObj) ? "Polygons"
  273.                       : (IP_IS_POLYLINE_OBJ(PObj) ? "Polylines"
  274.                                       : "Points"));
  275.     case IP_OBJ_NUMERIC:
  276.         return "Numeric";
  277.     case IP_OBJ_POINT:
  278.         return "Point";
  279.     case IP_OBJ_VECTOR:
  280.         return "Vector";
  281.     case IP_OBJ_PLANE:
  282.         return "Plane";
  283.     case IP_OBJ_CTLPT:
  284.         return "Control Point";
  285.     case IP_OBJ_MATRIX:
  286.         return "Matrix";
  287.     case IP_OBJ_STRING:
  288.         return "String";
  289.     case IP_OBJ_LIST_OBJ:
  290.         return "List Object";
  291.     case IP_OBJ_CURVE:
  292.         return "Curve";
  293.     case IP_OBJ_SURFACE:
  294.         return "Surface";
  295.     case IP_OBJ_TRIMSRF:
  296.         return "TrimSrf";
  297.     case IP_OBJ_TRIVAR:
  298.         return "Trivar";
  299.     case IP_OBJ_UNDEF:
  300.     default:
  301.         return "Undefined";
  302.     }
  303. }
  304.  
  305. /*****************************************************************************
  306. * DESCRIPTION:                                                               M
  307. * Print some useful information on a list of objects.                 M
  308. *                                                                            *
  309. * PARAMETERS:                                                                M
  310. *   PObj:      List of objects to print out.                                 M
  311. *                                                                            *
  312. * RETURN VALUE:                                                              M
  313. *   void                                                                     M
  314. *                                                                            *
  315. * KEYWORDS:                                                                  M
  316. *   PrintObjectList                                                          M
  317. *****************************************************************************/
  318. void PrintObjectList(IPObjectStruct *PObj)
  319. {
  320.     WndwInputWindowPutStr("");
  321.  
  322.     while (PObj != NULL) {
  323.     PrintObject(PObj);
  324.     PObj = PObj -> Pnext;
  325.     }
  326. }
  327.  
  328. /*****************************************************************************
  329. * DESCRIPTION:                                                               M
  330. * Coerce an object to a new object.                         M
  331. *                                                                            *
  332. * PARAMETERS:                                                                M
  333. *   PObj:        Object to coerce.                                           M
  334. *   RNewType:    New type for PObj.                                          M
  335. *                                                                            *
  336. * RETURN VALUE:                                                              M
  337. *   IPObjectStruct *:   The newly coerced object.                            M
  338. *                                                                            *
  339. * KEYWORDS:                                                                  M
  340. *   CoerceObjectTo                                                           M
  341. *****************************************************************************/
  342. IPObjectStruct *CoerceObjectTo(IPObjectStruct *PObj, RealType *RNewType)
  343. {
  344.     int NewType = REAL_TO_INT(*RNewType);
  345.     CagdCrvStruct *Crv;
  346.     CagdSrfStruct *Srf;
  347.     IPObjectStruct
  348.     *NewObj = NULL;
  349.  
  350.     switch (NewType) {
  351.     case KV_UNIFORM_PERIODIC:
  352.         WndwInputWindowPutStr("Conversion to periodic is not supported.");
  353.         return NULL;
  354.     case KV_UNIFORM_FLOAT:
  355.         if (IP_IS_CRV_OBJ(PObj)) {
  356.         if (CAGD_IS_PERIODIC_CRV(PObj -> U.Crvs)) {
  357.             NewObj =
  358.                 GenCRVObject(CnvrtPeriodic2FloatCrv(PObj -> U.Crvs));
  359.         }
  360.         else if (CAGD_IS_BSPLINE_CRV(PObj -> U.Crvs) &&
  361.              !BspCrvHasOpenEC(PObj -> U.Crvs)) {
  362.             NewObj = GenCRVObject(CagdCrvCopy(PObj -> U.Crvs));
  363.         }
  364.         else {
  365.             WndwInputWindowPutStr("Conversion to float legal only from periodic.");
  366.             return NULL;
  367.         }
  368.         }
  369.         else if (IP_IS_SRF_OBJ(PObj)) {
  370.         if (CAGD_IS_PERIODIC_SRF(PObj -> U.Srfs)) {
  371.             Srf = CnvrtPeriodic2FloatSrf(PObj -> U.Srfs);
  372.             NewObj = GenSRFObject(Srf);
  373.         }
  374.         else if (CAGD_IS_BSPLINE_SRF(PObj -> U.Srfs) &&
  375.              !BspSrfHasOpenEC(PObj -> U.Srfs)) {
  376.             NewObj = GenSRFObject(CagdSrfCopy(PObj -> U.Srfs));
  377.         }
  378.         else {
  379.             WndwInputWindowPutStr("Conversion to float legal only from periodic.");
  380.             return NULL;
  381.         }
  382.         }
  383.         break;
  384.     case KV_UNIFORM_OPEN:
  385.         if (IP_IS_CRV_OBJ(PObj)) {
  386.         if (CAGD_IS_BEZIER_CRV(PObj -> U.Crvs) ||
  387.             (CAGD_IS_BSPLINE_CRV(PObj -> U.Crvs) &&
  388.              BspCrvHasOpenEC(PObj -> U.Crvs))) {
  389.             NewObj = GenCRVObject(CagdCrvCopy(PObj -> U.Crvs));
  390.         }
  391.         else {
  392.             int NewCrv = FALSE;
  393.  
  394.             Crv = PObj -> U.Crvs;
  395.             if (CAGD_IS_PERIODIC_CRV(Crv)) {
  396.             Crv = CnvrtPeriodic2FloatCrv(Crv);
  397.             NewCrv = TRUE;
  398.             }
  399.  
  400.             NewObj = GenCRVObject(BspCrvOpenEnd(Crv));
  401.             if (NewCrv)
  402.                 CagdCrvFree(Crv);
  403.         }
  404.         }
  405.         else if (IP_IS_SRF_OBJ(PObj)) {
  406.         if (CAGD_IS_BEZIER_SRF(PObj -> U.Srfs) ||
  407.             (CAGD_IS_BSPLINE_SRF(PObj -> U.Srfs) &&
  408.              BspSrfHasOpenEC(PObj -> U.Srfs))) {
  409.             NewObj = GenSRFObject(CagdSrfCopy(PObj -> U.Srfs));
  410.         }
  411.         else {
  412.             int NewSrf = FALSE;
  413.  
  414.             Srf = PObj -> U.Srfs;
  415.             if (CAGD_IS_PERIODIC_SRF(Srf)) {
  416.             Srf = CnvrtPeriodic2FloatSrf(Srf);
  417.             NewSrf = TRUE;
  418.             }
  419.  
  420.             NewObj = GenSRFObject(BspSrfOpenEnd(Srf));
  421.             if (NewSrf)
  422.                 CagdSrfFree(Srf);
  423.         }
  424.         }
  425.         break;
  426.     default:
  427.         NewObj = IritPrsrCoerceObjectTo(PObj, NewType);
  428.         break;
  429.     }
  430.  
  431.     if (NewObj == NULL)
  432.     WndwInputWindowPutStr("Invalid coerction requested.");
  433.     return NewObj;
  434. }
  435.  
  436. /*****************************************************************************
  437. * DESCRIPTION:                                                               M
  438. * Saves an object in a data file.                              M
  439. *                                                                            *
  440. * PARAMETERS:                                                                M
  441. *   FileName:   Where to save PObj.                                          M
  442. *   PObj:       Object to save in a file.                                    M
  443. *                                                                            *
  444. * RETURN VALUE:                                                              M
  445. *   void                                                                     M
  446. *                                                                            *
  447. * KEYWORDS:                                                                  M
  448. *   SaveObjectInFile                                                         M
  449. *****************************************************************************/
  450. void SaveObjectInFile(char *FileName, IPObjectStruct *PObj)
  451. {
  452.     int Handler,
  453.     IsBinary = FALSE;
  454.     char FullFileName[LINE_LEN_LONG];
  455.  
  456.     if (FileName != NULL) {
  457.     strcpy(FullFileName, FileName);
  458.     if (strstr(FullFileName, ".bdt") ||
  459.         strstr(FullFileName, ".BDT")) {
  460.         /* Binary data file is requested. */
  461.         IsBinary = TRUE;
  462.     }
  463.     else if (strstr(FullFileName, ".dat") == NULL &&
  464.          strstr(FullFileName, ".DAT") == NULL)
  465.         strcat(FullFileName, ".dat");
  466.  
  467.     if ((Handler = IritPrsrOpenDataFile(FullFileName,
  468.                         FALSE, FALSE)) >= 0) {
  469.         IritPrsrPutObjectToHandler(Handler, PObj);
  470.         IritPrsrCloseStream(Handler, TRUE);
  471.     }
  472.     else {
  473.         sprintf(FullFileName, "Failed to open file \"%s\" for write.",
  474.             FileName);
  475.         WndwInputWindowPutStr(FullFileName);
  476.     }
  477.     }
  478.     else {
  479.     /* The output will go to WndwInputWindowPutStr2, not to stderr: */
  480.     IritPrsrSetPrintFunc(WndwInputWindowPutStr2);
  481.     IritPrsrPutObjectToFile(NULL, PObj);
  482.     IritPrsrSetPrintFunc(NULL);
  483.     }
  484. }
  485.  
  486. /*****************************************************************************
  487. * DESCRIPTION:                                                               M
  488. * Loads an object(s) from a data file.                         M
  489. *                                                                            *
  490. * PARAMETERS:                                                                M
  491. *   FileName:    Where to read object(s) from.                               M
  492. *                                                                            *
  493. * RETURN VALUE:                                                              M
  494. *   IPObjectStruct *:    Object(s) read from file FileName.                  M
  495. *                                                                            *
  496. * KEYWORDS:                                                                  M
  497. *   LoadObjectFromFile                                                       M
  498. *****************************************************************************/
  499. IPObjectStruct *LoadObjectFromFile(char *FileName)
  500. {
  501.     int Handler;
  502.     char FullFileName[LINE_LEN_LONG];
  503.  
  504.     if (FileName != NULL) {
  505.     strcpy(FullFileName, FileName);
  506.     if (strstr(FullFileName, ".bdt") == NULL &&
  507.         strstr(FullFileName, ".BDT") == NULL &&
  508.         strstr(FullFileName, ".dat") == NULL &&
  509.         strstr(FullFileName, ".DAT") == NULL)
  510.         strcat(FullFileName, ".dat");
  511.  
  512.     if ((Handler = IritPrsrOpenDataFile(FullFileName, TRUE, FALSE)) >= 0) {
  513.             IPObjectStruct
  514.                 *PObj = IritPrsrGetObjects(Handler);
  515.  
  516.         IritPrsrCloseStream(Handler, TRUE);
  517.  
  518.         if (PObj == NULL) {
  519.         char *ErrorMsg;
  520.  
  521.         if (IritPrsrParseError(0, &ErrorMsg)) {
  522.             WndwInputWindowPutStr("Data file parsing error:");
  523.             WndwInputWindowPutStr(ErrorMsg);
  524.         }
  525.         }
  526.         else
  527.         UpdateLoadedHierarchy(PObj, PObj);
  528.  
  529.         return PObj;
  530.     }
  531.     }
  532.  
  533.     sprintf(FullFileName, "Failed to open file \"%s\" for read.",
  534.         FileName);
  535.     WndwInputWindowPutStr(FullFileName);
  536.     return NULL;
  537. }
  538.  
  539. /*****************************************************************************
  540. * DESCRIPTION:                                                               *
  541. * Updates the hierarchy of loaded object.                     *
  542. *                                                                            *
  543. * PARAMETERS:                                                                *
  544. *   PObj:     Current, local, top of hierarchy.                              *
  545. *   Root:     Global, root, toop of hierarchy.                               *
  546. *                                                                            *
  547. * RETURN VALUE:                                                              *
  548. *   void                                                                     *
  549. *****************************************************************************/
  550. static void UpdateLoadedHierarchy(IPObjectStruct *PObj, IPObjectStruct *Root)
  551. {
  552.     if (PObj == NULL)
  553.     return;
  554.  
  555.     if (IP_IS_OLST_OBJ(PObj)) {
  556.     int i;
  557.     IPObjectStruct *PObjTmp;
  558.  
  559.     for (i = 0; (PObjTmp = ListObjectGet(PObj, i)) != NULL; i++)
  560.         UpdateLoadedHierarchy(PObjTmp, Root);
  561.     }
  562.  
  563.     if (PObj != Root && strlen(PObj -> Name) > 0) {
  564.     IPObjectStruct *OldPObj;
  565.  
  566.     if ((OldPObj = GetObject(PObj -> Name)) != NULL)
  567.         DeleteObject(OldPObj, TRUE);
  568.     InsertObject(PObj);
  569.     PObj -> Count++;
  570.     }
  571. }
  572.  
  573. /*****************************************************************************
  574. * DESCRIPTION:                                                               M
  575. * Error handler for loading andsaving of files.                              M
  576. *                                                                            *
  577. * PARAMETERS:                                                                M
  578. *   ErrorMsg:   Returns description of error if found one.                   M
  579. *                                                                            *
  580. * RETURN VALUE:                                                              M
  581. *   int:        TRUE if error found, FALSE otherwise.                        M
  582. *                                                                            *
  583. * KEYWORDS:                                                                  M
  584. *   LoadSaveObjectParseError                                                 M
  585. *****************************************************************************/
  586. int LoadSaveObjectParseError(char **ErrorMsg)
  587. {
  588.     int RetVal = IritPrsrParseError(0, ErrorMsg);
  589.  
  590.     if (!RetVal) {
  591.     *ErrorMsg = "";
  592.     return FALSE;
  593.     }
  594.     else
  595.     return TRUE;
  596. }
  597.  
  598. /*****************************************************************************
  599. * DESCRIPTION:                                                               M
  600. * Routine to construct a matrix out of a list of four lists of four numbers. M
  601. *                                                                            *
  602. * PARAMETERS:                                                                M
  603. *   LstObjList:   A list of four lists of four numbers.                      M
  604. *                                                                            *
  605. * RETURN VALUE:                                                              M
  606. *   IPObjectStruct *:   A matrix object.                                     M
  607. *                                                                            *
  608. * KEYWORDS:                                                                  M
  609. *   GenMatObjectGeneric                                                      M
  610. *****************************************************************************/
  611. IPObjectStruct *GenMatObjectGeneric(IPObjectStruct *LstObjList)
  612. {
  613.     MatrixType Mat;
  614.  
  615.     /* Generate the transformation matrix */
  616.     if (MatGenMatGeneric(LstObjList, Mat))
  617.     return GenMATObject(Mat);
  618.     else
  619.     return NULL;
  620. }
  621.  
  622. /*****************************************************************************
  623. * DESCRIPTION:                                                               *
  624. * Routine to generate a 4*4 matrix  by specifying all its 16 coefficients.   *
  625. *                                                                            *
  626. * PARAMETERS:                                                                *
  627. *   LstObjList:   A list of four lists of four numbers.                      M
  628. *   Mat:          Where to save the constructed matrix.                      *
  629. *                                                                            *
  630. * RETURN VALUE:                                                              *
  631. *   int:          TRUE if successful, FALSE otherwise.                       *
  632. *****************************************************************************/
  633. static int MatGenMatGeneric(IPObjectStruct *LstObjList, MatrixType Mat)
  634. {
  635.     int i, j;
  636.     IPObjectStruct *Row, *Col;
  637.  
  638.     MatGenUnitMat(Mat);                             /* Make it unit matrix, */
  639.  
  640.     if (!IP_IS_OLST_OBJ(LstObjList)) {
  641.     WndwInputWindowPutStr("Matrix: Not object list object!");
  642.     return FALSE;
  643.     }
  644.  
  645.     for (i = 0; i < 4; i++) {
  646.     if ((Row = ListObjectGet(LstObjList, i)) == NULL) {
  647.         WndwInputWindowPutStr("Matrix: Four rows expected, found less");
  648.         return FALSE;
  649.     }
  650.     if (!IP_IS_OLST_OBJ(Row)) {
  651.         WndwInputWindowPutStr("None list object found in list");
  652.         return FALSE;
  653.     }
  654.  
  655.     for (j = 0; j < 4; j++) {
  656.         if ((Col = ListObjectGet(Row, j)) == NULL) {
  657.         WndwInputWindowPutStr("Matrix: Four columns expected, found less.");
  658.         return FALSE;
  659.         }
  660.  
  661.         if (!IP_IS_NUM_OBJ(Col)) {
  662.         WndwInputWindowPutStr("Numeric value expected.");
  663.         return FALSE;
  664.         }
  665.  
  666.         Mat[i][j] = Col -> U.R;
  667.     }
  668.     }
  669.     return TRUE;
  670. }
  671.  
  672. /*****************************************************************************
  673. * DESCRIPTION:                                                               M
  674. * Generates a BOX primitive for IRIT.                                        M
  675. *                                                                            *
  676. * PARAMETERS:                                                                M
  677. *   Pt:          Low end corner of BOX.                                      M
  678. *   WidthX:      Width of BOX (X axis).                                      M
  679. *   WidthY:      Depth of BOX( Y axis).                                      M
  680. *   WidthZ:      Height of BOX( Z axis).                                     M
  681. *                                                                            *
  682. * RETURN VALUE:                                                              M
  683. *   IPObjectStruct *:   A BOX primitive.                                     M
  684. *                                                                            *
  685. * KEYWORDS:                                                                  M
  686. *   GenBOXObject                                                             M
  687. *****************************************************************************/
  688. IPObjectStruct *GenBOXObject(VectorType Pt,
  689.                  RealType *WidthX,
  690.                  RealType *WidthY,
  691.                  RealType *WidthZ)
  692. {
  693.     PrimSetResolution(GetResolution(TRUE));
  694.  
  695.     return PrimGenBOXObject(Pt, *WidthX, *WidthY, *WidthZ);
  696. }
  697.  
  698. /*****************************************************************************
  699. * DESCRIPTION:                                                               M
  700. * Generates a GBOX primitive for IRIT.                                       M
  701. *                                                                            *
  702. * PARAMETERS:                                                                M
  703. *   Pt:                Low end corner of GBOX.                     M
  704. *   Dir1, Dir2, Dir3:  Three independent directional vectors to define GBOX. M
  705. *                                                                            *
  706. * RETURN VALUE:                                                              M
  707. *   IPObjectStruct *:   A GBOX primitive.                                    M
  708. *                                                                            *
  709. * KEYWORDS:                                                                  M
  710. *   GenGBOXObject                                                            M
  711. *****************************************************************************/
  712. IPObjectStruct *GenGBOXObject(VectorType Pt,
  713.                   VectorType Dir1,
  714.                   VectorType Dir2,
  715.                   VectorType Dir3)
  716. {
  717.     PrimSetResolution(GetResolution(TRUE));
  718.  
  719.     return PrimGenGBOXObject(Pt, Dir1, Dir2, Dir3);
  720. }
  721.  
  722. /*****************************************************************************
  723. * DESCRIPTION:                                                               M
  724. * Generates a CONE primitive for IRIT.                                       M
  725. *                                                                            *
  726. * PARAMETERS:                                                                M
  727. *   Pt:         Center location of Base of CONE.                             M
  728. *   Dir:        Direction and distance from Pt to apex of CONE.              M
  729. *   R:          Radius of Base of the cone.                                  M
  730. *                                                                            *
  731. * RETURN VALUE:                                                              M
  732. *   IPObjectStruct *:   A CONE primitive.                                    M
  733. *                                                                            *
  734. * KEYWORDS:                                                                  M
  735. *   GenCONEObject                                                            M
  736. *****************************************************************************/
  737. IPObjectStruct *GenCONEObject(VectorType Pt, VectorType Dir, RealType *R)
  738. {
  739.     PrimSetResolution(GetResolution(TRUE));
  740.  
  741.     return PrimGenCONEObject(Pt, Dir, *R);
  742. }
  743.  
  744. /*****************************************************************************
  745. * DESCRIPTION:                                                               M
  746. * Generates a CONE2 primitive for IRIT.                                      M
  747. *                                                                            *
  748. * PARAMETERS:                                                                M
  749. *   Pt:      Center location of Base of CON2.                                M
  750. *   Dir:     Direction and distance from Pt to center of other base of CON2. M
  751. *   R1, R2:  Two base radii of the truncated CON2                            M
  752. *                                                                            *
  753. * RETURN VALUE:                                                              M
  754. *   IPObjectStruct *:   A CONE2 primitive.                                   M
  755. *                                                                            *
  756. * KEYWORDS:                                                                  M
  757. *   GenCONE2Object                                                           M
  758. *****************************************************************************/
  759. IPObjectStruct *GenCONE2Object(VectorType Pt,
  760.                    VectorType Dir,
  761.                    RealType *R1,
  762.                    RealType *R2)
  763. {
  764.     PrimSetResolution(GetResolution(TRUE));
  765.  
  766.     return PrimGenCONE2Object(Pt, Dir, *R1, *R2);
  767. }
  768.  
  769. /*****************************************************************************
  770. * DESCRIPTION:                                                               M
  771. * Generates a CYLINder primitive for IRIT.                                   M
  772. *                                                                            *
  773. * PARAMETERS:                                                                M
  774. *   Pt:         Center location of Base of CYLINder.                         M
  775. *   Dir:        Direction and distance from Pt to other base of cylinder.    M
  776. *   R:          Radius of Base of the cylinder.                              M
  777. *                                                                            *
  778. * RETURN VALUE:                                                              M
  779. *   IPObjectStruct *:   A CYLIN primitive.                                   M
  780. *                                                                            *
  781. * KEYWORDS:                                                                  M
  782. *   GenCYLINObject                                                           M
  783. *****************************************************************************/
  784. IPObjectStruct *GenCYLINObject(VectorType Pt, VectorType Dir, RealType *R)
  785. {
  786.     PrimSetResolution(GetResolution(TRUE));
  787.  
  788.     return PrimGenCYLINObject(Pt, Dir, *R);
  789. }
  790.  
  791. /*****************************************************************************
  792. * DESCRIPTION:                                                               M
  793. * Generates a SPHERE primitive for IRIT.                                     M
  794. *                                                                            *
  795. * PARAMETERS:                                                                M
  796. *   Center:   Center location of SPHERE.                                     M
  797. *   R         Radius of sphere.                                              M
  798. *                                                                            *
  799. * RETURN VALUE:                                                              M
  800. *   IPObjectStruct *:   A SPHERE primitive.                                  M
  801. *                                                                            *
  802. * KEYWORDS:                                                                  M
  803. *   GenSPHEREObject                                                          M
  804. *****************************************************************************/
  805. IPObjectStruct *GenSPHEREObject(VectorType Center, RealType *R)
  806. {
  807.     PrimSetResolution(GetResolution(TRUE));
  808.  
  809.     return PrimGenSPHEREObject(Center, *R);
  810. }
  811.  
  812. /*****************************************************************************
  813. * DESCRIPTION:                                                               M
  814. * Generates a TORUS primitive for IRIT.                                      M
  815. *                                                                            *
  816. * PARAMETERS:                                                                M
  817. *   Center:  Center location of the TORUS primitive.                         M
  818. *   Normal:  Normal to the major plane of the torus.                         M
  819. *   Rmajor:  Major radius of torus.                                          M
  820. *   Rminor:  Minor radius of torus.                                          M
  821. *                                                                            *
  822. * RETURN VALUE:                                                              M
  823. *   IPObjectStruct *:   A TOURS primitive.                                   M
  824. *                                                                            *
  825. * KEYWORDS:                                                                  M
  826. *   GenTORUSObject                                                           M
  827. *****************************************************************************/
  828. IPObjectStruct *GenTORUSObject(VectorType Center,
  829.                    VectorType Normal,
  830.                    RealType *Rmajor,
  831.                    RealType *Rminor)
  832. {
  833.     PrimSetResolution(GetResolution(TRUE));
  834.  
  835.     return PrimGenTORUSObject(Center, Normal, *Rmajor, *Rminor);
  836. }
  837.  
  838. /*****************************************************************************
  839. * DESCRIPTION:                                                               M
  840. * Generates a POLYDISK primitive for IRIT.                                   M
  841. *                                                                            *
  842. * PARAMETERS:                                                                M
  843. *   N:         Normal to the plane this disk included in.                    M
  844. *   T:         A translation factor of the center of the disk.               M
  845. *   R:         Radius of teh disk.                                           M
  846. *                                                                            *
  847. * RETURN VALUE:                                                              M
  848. *   IPObjectStruct *:  A POLYDISK primitive.                                 M
  849. *                                                                            *
  850. * KEYWORDS:                                                                  M
  851. *   GenPOLYDISKObject                                                        M
  852. *****************************************************************************/
  853. IPObjectStruct *GenPOLYDISKObject(VectorType N, VectorType T, RealType *R)
  854. {
  855.     PrimSetResolution(GetResolution(TRUE));
  856.  
  857.     return PrimGenPOLYDISKObject(N, T, *R);
  858. }
  859.  
  860. /*****************************************************************************
  861. * DESCRIPTION:                                                               M
  862. * Generates a POLYGON primitive for IRIT.                                    M
  863. *                                                                            *
  864. * PARAMETERS:                                                                M
  865. *   PObjList:     List of vertices/points to construct as a polygon/line.    M
  866. *   RIsPolyline:   If TRUE, make a polyline, otherwise a polygon.            M
  867. *                                                                            *
  868. * RETURN VALUE:                                                              M
  869. *   IPObjectStruct *:   A POLYGON primitive.                                 M
  870. *                                                                            *
  871. * KEYWORDS:                                                                  M
  872. *   GenPOLYGONObject                                                         M
  873. *****************************************************************************/
  874. IPObjectStruct *GenPOLYGONObject(IPObjectStruct *PObjList,
  875.                  RealType *RIsPolyline)
  876. {
  877.     PrimSetResolution(GetResolution(TRUE));
  878.  
  879.     return PrimGenPOLYGONObject(PObjList, REAL_PTR_TO_INT(RIsPolyline));
  880. }
  881.  
  882. /*****************************************************************************
  883. * DESCRIPTION:                                                               M
  884. * Creates an object from a list of polys.                                    M
  885. *                                                                            *
  886. * PARAMETERS:                                                                M
  887. *   PObjList:      List of polygonal objects.                                M
  888. *                                                                            *
  889. * RETURN VALUE:                                                              M
  890. *   IPObjectStruct *:   A single object containing all polygons in all       M
  891. *                       provided objects, by a simple union.                 M
  892. *                                                                            *
  893. * KEYWORDS:                                                                  M
  894. *   GenObjectFromPolyList                                                    M
  895. *****************************************************************************/
  896. IPObjectStruct *GenObjectFromPolyList(IPObjectStruct *PObjList)
  897. {
  898.     PrimSetResolution(GetResolution(TRUE));
  899.  
  900.     return PrimGenObjectFromPolyList(PObjList);
  901. }
  902.  
  903. /*****************************************************************************
  904. * DESCRIPTION:                                                               *
  905. * Not supported.                                                             *
  906. *                                                                            *
  907. * PARAMETERS:                                                                *
  908. *   PObj:                                                                    *
  909. *                                                                            *
  910. * RETURN VALUE:                                                              *
  911. *   IPObjectStruct *:                                                        *
  912. *****************************************************************************/
  913. IPObjectStruct *GenCROSSECObject(IPObjectStruct *PObj)
  914. {
  915.     PrimSetResolution(GetResolution(TRUE));
  916.  
  917.     return PrimGenCROSSECObject(PObj);
  918. }
  919.  
  920. /*****************************************************************************
  921. * DESCRIPTION:                                                               M
  922. * Generates a SURFREV primitive for IRIT.                                    M
  923. *                                                                            *
  924. * PARAMETERS:                                                                M
  925. *   Cross:     To rotate around the Z axis forming a surface of revolution.  M
  926. *                                                                            *
  927. * RETURN VALUE:                                                              M
  928. *   IPObjectStruct *:   A SURFREV primitive.                                 M
  929. *                                                                            *
  930. * KEYWORDS:                                                                  M
  931. *   GenSURFREVObject                                                         M
  932. *****************************************************************************/
  933. IPObjectStruct *GenSURFREVObject(IPObjectStruct *Cross)
  934. {
  935.     PrimSetResolution(GetResolution(TRUE));
  936.  
  937.     return PrimGenSURFREVObject(Cross);
  938. }
  939.  
  940. /*****************************************************************************
  941. * DESCRIPTION:                                                               M
  942. * Generates an EXTRUDE primitive for IRIT.                                   M
  943. *                                                                            *
  944. * PARAMETERS:                                                                M
  945. *   Cross:     To extrude in direction Dir.                                  M
  946. *   Dir:       Direction and magnitude of extrusion.                         M
  947. *                                                                            *
  948. * RETURN VALUE:                                                              M
  949. *   IPObjectStruct *:    An EXTRUDE primitive.                               M
  950. *                                                                            *
  951. * KEYWORDS:                                                                  M
  952. *   GenEXTRUDEObject                                                         M
  953. *****************************************************************************/
  954. IPObjectStruct *GenEXTRUDEObject(IPObjectStruct *Cross, VectorType Dir)
  955. {
  956.     PrimSetResolution(GetResolution(TRUE));
  957.  
  958.     return PrimGenEXTRUDEObject(Cross, Dir);
  959. }
  960.